import CryptoJS from "crypto-js";

export default class UtilAes{
    static _key = CryptoJS.enc.Utf8.parse("jiankangwuyouabc");
    static encrypt(txt){
        var encryptResult = CryptoJS.AES.encrypt(txt, UtilAes._key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        // const base64Cipher = encryptResult.ciphertext.toString(CryptoJS.enc.Base64);
        return encryptResult.toString();
    }
    static decrypt(bf){
        bf = bf.replace(/\n/g, "");//这里因为 base64 没有间隔
        var bytes = CryptoJS.AES.decrypt(bf, UtilAes._key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return CryptoJS.enc.Utf8.stringify(bytes);
    }
}
